/**
 * Copyright (c) 2022 coreops All rights reserved.
 * <p>
 *
 * <p>
 * 版权所有，侵权必究！
 */

package edu.nwpu.zya.coreops.common.utils;

import edu.nwpu.zya.coreops.common.validator.group.AliyunGroup;
import edu.nwpu.zya.coreops.common.validator.group.QcloudGroup;
import edu.nwpu.zya.coreops.common.validator.group.QiniuGroup;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * 常量
 *
 * @author zhouyuang 742025491@qq.com
 */
public class Constant {
    /**
     * 超级管理员ID
     */
    public static final int SUPER_ADMIN = 1;
    /**
     * 当前页码
     */
    public static final String PAGE = "page";
    /**
     * 每页显示记录数
     */
    public static final String LIMIT = "limit";
    /**
     * 排序字段
     */
    public static final String ORDER_FIELD = "sidx";
    /**
     * 排序方式
     */
    public static final String ORDER = "order";
    /**
     * 升序
     */
    public static final String ASC = "asc";


    /**
     * elasticsearch聚合查询名称
     */
    public enum ESAggName{
        MINUTE_INTERVAL("minuteIntervalAgg","按分钟间隔聚合");


        private String name;
        private String description;

        ESAggName(String name, String description) {
            this.name= name;
            this.description = description;
        }

        public String getValue() {
            return name;
        }

        public String getMsg() {
            return description;
        }
    }

    public enum RunningStatus {
        RUNNING(1,"正在运行"),
        PAUSE(0,"停止运行");

        private Integer value;
        private String msg;

        RunningStatus(Integer value, String msg) {
            this.value = value;
            this.msg = msg;
        }

        public Integer getValue() {
            return value;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 告警状态
     */
    public enum AlertStatus{
        NORMAL(0,"正常状态"),
        ALERTING(1,"告警状态"),
        DISABLED(2,"禁用状态");

        private Integer value;
        private String msg;

        AlertStatus(Integer value, String msg) {
            this.value = value;
            this.msg = msg;
        }

        public Integer getValue() {
            return value;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 告警历史状态
     */
    public enum AlertHistoryStatus{
        OCCUR(1,"发生告警"),
        RECOVERY(2,"告警恢复");

        private Integer value;
        private String msg;

        AlertHistoryStatus(Integer value, String msg) {
            this.value = value;
            this.msg = msg;
        }

        public Integer getValue() {
            return value;
        }

        public String getMsg() {
            return msg;
        }
    }
    /**
     * 比较类型
     */
    public enum CompareType{
        GT(">","大于"),
        GTE(">=","大于等于"),
        LT("<","小于"),
        LTE("<=","小于等于"),
        EQ("=","等于"),
        NE("!=","不等于");


        private String type;
        private String description;

        CompareType(String type, String description) {
            this.type = type;
            this.description = description;
        }

        public String getValue() {
            return type;
        }

        public String getMsg() {
            return description;
        }

    }

    /**
     * 指标单位类型
     */
    public enum MetricUnitType {
        Percent("%", "百分比"),
        ByteRate("Byte/s", "字节/秒"),
        CountRate("Count/Second", "次/秒"),
        Byte("Byte", "字节数"),
        KBytes("KBytes","千字节"),
        BitRate("bit/s", "比特/秒"),
        Count("Count", "次"),
        Second("Second", "秒"),
        MS("ms","毫秒"),
        MB("MB", "兆字节");


        private String unit;
        private String description;

        MetricUnitType(String unit, String description) {
            this.unit = unit;
            this.description = description;
        }

        public String getValue() {
            return unit;
        }

        public String getMsg() {
            return description;
        }

    }

    /**
     * 实例类型
     */
    public enum InstanceType {
        ECS(0, "云主机ECS"), RDS(1, "数据库RDS"), APP(2, "应用服务APP");

        private Integer value;
        private String msg;

        InstanceType(Integer value, String msg) {
            this.value = value;
            this.msg = msg;
        }

        public Integer getValue() {
            return value;
        }

        public String getMsg() {
            return msg;
        }

    }

    /**
     * 指标聚合类型
     */
    public enum AggType {
        AVG(0, "平均值"), MIN(1, "最小值"), MAX(2, "最大值");

        private Integer value;
        private String msg;

        AggType(Integer value, String msg) {
            this.value = value;
            this.msg = msg;
        }

        public Integer getValue() {
            return value;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 菜单类型
     *
     * @author chenshun
     * @email 742025491@qq.com
     * @date 2016年11月15日 下午1:24:29
     */
    public enum MenuType {
        /**
         * 目录
         */
        CATALOG(0),
        /**
         * 菜单
         */
        MENU(1),
        /**
         * 按钮
         */
        BUTTON(2);

        private int value;

        MenuType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    /**
     * 定时任务状态
     *
     * @author chenshun
     * @email 742025491@qq.com
     * @date 2016年12月3日 上午12:07:22
     */
    public enum ScheduleStatus {
        /**
         * 正常
         */
        NORMAL(0),
        /**
         * 暂停
         */
        PAUSE(1);

        private int value;

        ScheduleStatus(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    /**
     * 云服务商
     */
    public enum CloudService {
        /**
         * 七牛云
         */
        QINIU(1, QiniuGroup.class),
        /**
         * 阿里云
         */
        ALIYUN(2, AliyunGroup.class),
        /**
         * 腾讯云
         */
        QCLOUD(3, QcloudGroup.class);

        private int value;

        private Class<?> validatorGroupClass;

        CloudService(int value, Class<?> validatorGroupClass) {
            this.value = value;
            this.validatorGroupClass = validatorGroupClass;
        }

        public int getValue() {
            return value;
        }

        public Class<?> getValidatorGroupClass() {
            return this.validatorGroupClass;
        }

        public static CloudService getByValue(Integer value) {
            Optional<CloudService> first = Stream.of(CloudService.values()).filter(cs -> value.equals(cs.value)).findFirst();
            if (!first.isPresent()) {
                throw new IllegalArgumentException("非法的枚举值:" + value);
            }
            return first.get();
        }
    }

    /**
     * app数据在elasticsearch中的mappings
     */
    public static final String APP_MAPPING = "{\n" +
            "    \"properties\": {\n" +
            "      \"instanceId\": {\n" +
            "        \"type\": \"keyword\"\n" +
            "      },\n" +
            "      \"time\": {\n" +
            "        \"type\": \"date\"\n" +
            "      },\n" +
            "      \"Latency\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"SumQPS\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"NetIn\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"NetOut\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"code2XX\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"code4XX\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"code5XX\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"CpuIdle\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"CpuIoWait\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"CpuSystem\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"DiskFreeBytes\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"DiskUsedRatio\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"MemFreeBytes\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"NetInErr\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"NetOutErr\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      }\n" +
            "    }\n" +
            "  }";

    /**
     * rds数据在elasticsearch中的mappings
     */
    public static final String RDS_MAPPING="{\n" +
            "    \"properties\": {\n" +
            "      \"instanceId\": {\n" +
            "        \"type\": \"keyword\"\n" +
            "      },\n" +
            "      \"time\": {\n" +
            "        \"type\": \"date\"\n" +
            "      },\n" +
            "      \"ConnectionUsage\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"CpuUsage\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"DataDelay\": {\n" +
            "        \"type\": \"double\"\n" +
            "      },\n" +
            "      \"DiskUsage\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"IOPSUsage\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"MemoryUsage\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"ComDelete\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"ComInsert\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"ComInsertSelect\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"ComSelect\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"ComUpdate\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"DataDiskSize\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"IbufDirtyRatio\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"IbufReadHit\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"IbufRequestR\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"IbufRequestW\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"IbufUseRatio\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"NetworkInNew\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"NetworkOutNew\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"OtherDiskSize\": {\n" +
            "        \"type\": \"float\"\n" +
            "      },\n" +
            "      \"QPS\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"TPS\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      },\n" +
            "      \"ThreadsConnected\": {\n" +
            "        \"type\": \"integer\"\n" +
            "      }\n" +
            "    }\n" +
            "  }";
    /**
     * ecs数据在elasticsearch中的mappings
     */
    public static final String ECS_MAPPING = "{\n" +
            "\t\"properties\": {\n" +
            "\t\t\"instanceId\": {\n" +
            "\t\t\t\"type\": \"keyword\"\n" +
            "\t\t},\n" +
            "\t\t\"time\": {\n" +
            "\t\t\t\"type\": \"date\"\n" +
            "\t\t},\n" +
            "\t\t\"MemoryUtilization\": {\n" +
            "\t\t\t\"type\": \"float\"\n" +
            "\t\t},\n" +
            "\t\t\"CPUUtilization\": {\n" +
            "\t\t\t\"type\": \"float\"\n" +
            "\t\t},\n" +
            "\t\t\"DiskReadBPS\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"DiskReadIOPS\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"DiskWriteBPS\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"DiskWriteIOPS\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"InternetIn\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"InternetInRate\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"InternetOut\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"InternetOutRate\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"InternetOutRate_Percent\": {\n" +
            "\t\t\t\"type\": \"float\"\n" +
            "\t\t},\n" +
            "\t\t\"IntranetIn\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"IntranetInRate\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"IntranetOut\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"IntranetOutRate\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"concurrentConnections\": {\n" +
            "\t\t\t\"type\": \"integer\"\n" +
            "\t\t},\n" +
            "\t\t\"packetInDropRates\": {\n" +
            "\t\t\t\"type\": \"float\"\n" +
            "\t\t},\n" +
            "\t\t\"packetOutDropRates\": {\n" +
            "\t\t\t\"type\": \"float\"\n" +
            "\t\t}\n" +
            "\t}\n" +
            "}";

}
